Strict

Import mojo
Import agfx

Global GAME_SplashScreen:TGAME_SplashScreen
Global GAME_TitleScreen:TGAME_TitleScreen
Global GAME_MenuScreen:TGAME_MenuScreen
Global GAME_GameScreen:TGAME_GameScreen
Global GAME_ResultScreen:TGAME_ResultScreen
Global GAME_HelpScreen:TGAME_HelpScreen

Global fade_speed:Int = 30

Class TAgfx_test_app Extends TFramework

	Method OnCreate:Int()
		
		'DEVICE.SetFps(30)		' default FPS is 60
		
		Super.OnCreate()
		
		Self.debug_On = True
		
		DISPLAY.SetVirtualSize(320,480)
		
		GAME_SplashScreen = New TGAME_SplashScreen
		
		IMAGES.Load("AGFX_splash_320x480.png","SPLASH",False)
		IMAGES.Load("GAME_splash_320x480.png","GAMESPLASH",False)
		IMAGES.Load("bkg_320x480.png","MENUBKG",False)
		IMAGES.Load("game_bkg.png","GAMEBKG",False)
		
		IMAGES.LoadAnim("btn_start.png",96,32,3,null,False)
		IMAGES.LoadAnim("btn_score.png",96,32,3,null,False)
		IMAGES.LoadAnim("btn_help.png",96,32,3,null,False)
		IMAGES.LoadAnim("btn_exit.png",96,32,3,null,False)
		
		
		GAME_SplashScreen.Prepare()
		
		GAME_TitleScreen = New TGAME_TitleScreen
		
		GAME_MenuScreen = New TGAME_MenuScreen
		
		GAME_GameScreen = New TGAME_GameScreen
		
		GAME_ResultScreen = New TGAME_ResultScreen
		
		GAME_HelpScreen = New TGAME_HelpScreen
				
		Return 0
	End
	
	
End



'| ******************************************************************
'| SPLASH SCREEN
'| ******************************************************************

Class TGAME_SplashScreen Extends TScreen
	
	Field splashBkg:TImage
	
	Method Start:Void()		
		Self.name = "SPLASH"
		Self.splashBkg = IMAGES.Find("SPLASH")
		APP.fadeScreen.Start(fade_speed, False)
	End
	
	Method Update:Void()
		If MOUSE.Hit(MOUSE_LEFT)
			APP.fadeScreen.Start(fade_speed, True)
			APP.nextScreen = GAME_TitleScreen
		End
	End
	
	Method Render:Void()
		Self.splashBkg.Draw(0,0)		
	End
End

'| ******************************************************************
'| TITLE SCREEN
'| ******************************************************************

Class TGAME_TitleScreen Extends TScreen
	
	Field titleBkg:TImage
	
	Method Start:Void()	
		Self.name = "TITLE"	
		Self.titleBkg = IMAGES.Find("GAMESPLASH")
		APP.fadeScreen.Start(fade_speed, False)
	End
	
	Method Update:Void()
	
		If MOUSE.Hit(MOUSE_LEFT)
			APP.fadeScreen.Start(fade_speed, True)
			APP.nextScreen = GAME_MenuScreen
		End
		
		If KeyHit(KEY_ESCAPE)
			APP.fadeScreen.Start(fade_speed, True)
			APP.nextScreen = APP.exitScreen
		End
	End
	
	Method Render:Void()	
		Self.titleBkg.Draw(0,0)
	End
	
End

'| ******************************************************************
'| MENU SCREEN BUTTONS CALLBACK on HIT
'| ******************************************************************

' [START]

Class btn_start_press Extends TCallback

	Field b:TGUIButton

	Method New(obj:TGUIButton)
		Self.b = obj
	End

	Method Call:Void()
		Print("Button "+Self.b.name+" pressed")
		
		APP.fadeScreen.Start(fade_speed, True)
		APP.nextScreen = GAME_GameScreen

	End

End

' [SCORE]

Class btn_score_press Extends TCallback

	Field b:TGUIButton

	Method New(obj:TGUIButton)
		Self.b = obj
	End

	Method Call:Void()
		APP.fadeScreen.Start(fade_speed, True)
		APP.nextScreen = GAME_ResultScreen 
	
	End

End

' [HELP]

Class btn_help_press Extends TCallback

	Field b:TGUIButton

	Method New(obj:TGUIButton)
		Self.b = obj
	End

	Method Call:Void()
		APP.fadeScreen.Start(fade_speed, True)
		APP.nextScreen = GAME_HelpScreen 

	End

End

' [EXIT]

Class btn_exit_press Extends TCallback

	Field b:TGUIButton

	Method New(obj:TGUIButton)
		Self.b = obj
	End

	Method Call:Void()
		Print("Button "+Self.b.name+" pressed")
		
		APP.fadeScreen.Start(fade_speed, True)
		APP.nextScreen = APP.exitScreen

	End

End


'| ******************************************************************
'| MENU SCREEN
'| ******************************************************************

Class TGAME_MenuScreen Extends TScreen
	
	Field menuBkg:TImage
	
	Field btn_START:TGUIButton
	Field btn_SCORE:TGUIButton
	Field btn_HELP:TGUIButton
	Field btn_EXIT:TGUIButton
	
	Method Start:Void()	
		Self.name = "MENU"	
		Self.menuBkg = IMAGES.Find("MENUBKG")
		APP.fadeScreen.Start(fade_speed, False)	
		
		Self.btn_START = New TGUIButton("BTN_START","btn_start",DISPLAY.VSCREEN_HALF_WIDTH-48,320+32*0,True)
		Self.btn_START.OnHit = New btn_start_press(Self.btn_START)
				
		Self.btn_SCORE = New TGUIButton("BTN_SCORE","btn_score",DISPLAY.VSCREEN_HALF_WIDTH-48,320+32*1,True)
		Self.btn_SCORE.OnHit = New btn_score_press(Self.btn_SCORE)
		
		Self.btn_HELP = New TGUIButton("BTN_HELP","btn_help",DISPLAY.VSCREEN_HALF_WIDTH-48,320+32*2,True)
		Self.btn_HELP.OnHit = New btn_help_press(Self.btn_HELP)
		
		Self.btn_EXIT = New TGUIButton("BTN_EXIT","btn_exit",DISPLAY.VSCREEN_HALF_WIDTH-48,320+32*3,True)
		Self.btn_EXIT.OnHit = New btn_exit_press(Self.btn_EXIT)
		
	End
	
	Method Update:Void()
		
		Self.btn_START.Update()
		Self.btn_SCORE.Update()
		Self.btn_HELP.Update()
		Self.btn_EXIT.Update()
	End
	
	Method Render:Void()
		
		Self.menuBkg.Draw(0,0)
		
		SetBlend(0)
		
		Self.btn_START.Draw()
		Self.btn_SCORE.Draw()
		Self.btn_HELP.Draw()
		Self.btn_EXIT.Draw()
		
		SetBlend(0)
	End
End

'| ******************************************************************
'| GAME SCREEN
'| ******************************************************************

Class TGAME_GameScreen Extends TScreen
	
	Field gameBkg:TImage
	
	Method Start:Void()		
		Self.name = "GAME"
		Self.gameBkg = IMAGES.Find("GAMEBKG")
		APP.fadeScreen.Start(fade_speed, False)	
	End
	
	Method Update:Void()
		If MOUSE.Hit(MOUSE_LEFT)
			APP.fadeScreen.Start(fade_speed, True)
		
		End
		
		If KeyHit(KEY_ESCAPE)
			APP.fadeScreen.Start(fade_speed, True)
			APP.nextScreen = GAME_MenuScreen
		End
	End
	
	Method Render:Void()
		Self.gameBkg.Draw(0,0)
		DrawText "Play!", DISPLAY.VSCREEN_HALF_WIDTH, DISPLAY.VSCREEN_HALF_HEIGHT + 20, 0.5, 0.5
		DrawText "Escape to Menu!", DISPLAY.VSCREEN_HALF_WIDTH, DISPLAY.VSCREEN_HALF_HEIGHT + 40, 0.5, 0.5	
	End
End

'| ******************************************************************
'| RESULT SCREEN
'| ******************************************************************

Class TGAME_ResultScreen Extends TScreen
	
	Field resultBkg:TImage
	
	Method Start:Void()
		Self.name = "RESULT"
		Self.resultBkg = IMAGES.Find("MENUBKG")
		APP.fadeScreen.Start(fade_speed, False)			
	End
	
	Method Update:Void()
		If KeyHit(KEY_ESCAPE)
			APP.fadeScreen.Start(fade_speed, True)
			APP.nextScreen = GAME_MenuScreen
		End
	End
	
	Method Render:Void()
		Self.resultBkg.Draw(0,0)
		DrawText "SCORE", DISPLAY.VSCREEN_HALF_WIDTH, DISPLAY.VSCREEN_HALF_HEIGHT + 20, 0.5, 0.5
		DrawText "Escape to Menu!", DISPLAY.VSCREEN_HALF_WIDTH, DISPLAY.VSCREEN_HALF_HEIGHT + 40, 0.5, 0.5		
	End
End

'| ******************************************************************
'| HELP SCREEN
'| ******************************************************************

Class TGAME_HelpScreen Extends TScreen
	

		Field helpBkg:TImage
	
	Method Start:Void()
		Self.name = "HELP"
		Self.helpBkg = IMAGES.Find("MENUBKG")
		APP.fadeScreen.Start(fade_speed, False)			
	End
	
	Method Update:Void()
	
		If KeyHit(KEY_ESCAPE)
			APP.fadeScreen.Start(fade_speed, True)
			APP.nextScreen = GAME_MenuScreen
		End
	End
	
	Method Render:Void()
		Self.helpBkg.Draw(0,0)
		DrawText "HELP", DISPLAY.VSCREEN_HALF_WIDTH, DISPLAY.VSCREEN_HALF_HEIGHT + 20, 0.5, 0.5
		DrawText "Escape to Menu!", DISPLAY.VSCREEN_HALF_WIDTH, DISPLAY.VSCREEN_HALF_HEIGHT + 40, 0.5, 0.5		
	End
	
End

